<?php

/**
 * 系统日志管理
 * File Name：SystemlogController.php
 * File Encoding：UTF-8
 * File New Time：2014-5-16 9:03:55
 * Author：水平凡
 * Mailbox：admin@abc3210.com
 */
class SystemlogController extends AdminBase {

    //操作日志
    public function actionIndex() {
        //搜索
        if (IS_POST) {
            foreach ($_POST as $k => $v) {
                if ($v == '') {
                    unset($_POST[$k]);
                }
            }
            $this->redirect(AdminBase::U('index', $_POST));
            exit;
        }
        $where = array(
            'order' => 'id desc'
        );
        $status = $_GET['status'];
        if ($status != '') {
            $where['status'] = array('EQ', (int) $status);
        }
        $uid = (int) $_GET['uid'];
        if ($uid) {
            $where['uid'] = array('EQ', $uid);
        }
        $ip = trim($_GET['ip']);
        if ($ip) {
            $where['ip'] = array('EQ', $ip);
        }
        $start_time = trim($_GET['start_time']);
        if ($start_time) {
            $where['time'] = array('EGT', strtotime($start_time));
            $end_time = trim($_GET['end_time']);
            if ($end_time) {
                $where['time'] = array('ELT', strtotime($start_time));
            }
        }

        $model = AdminOperationLog::model();
        $criteria = $model->where($where);
        //分页数
        $limit = 20;
        //分页
        $pageId = isset($_GET['page']) ? (int) $_GET['page'] : 1;
        $count = $model->count($criteria);
        //分页
        $page = AdminBase::page($count, $limit, $pageId);
        //查询信息
        $criteria->limit = $page->listRows;
        $criteria->offset = $page->firstRow;
        $data = $model->findAll($criteria);

        $this->assign("Page", $page->show());
        $this->assign('data', $data);
        $this->assign('count', $count);
        $this->render();
    }

    //删除一个月前的日志
    public function actionAmonthago() {
        if (AdminOperationLog::model()->deleteAMonthago()) {
            $this->success('删除日志成功！');
        } else {
            $this->error('日志删除失败！');
        }
    }

}
